﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Koopakiller.Numerics.Test
{
    [TestClass]
    public class GenericTest
    {
        [TestMethod, TestCategory("Ext: System.Generic:CopyDictionary")]
        public void CopyDictionary1()
        {
            //? structure
            Dictionary<int, int> dic = new Dictionary<int, int>();
            dic.Add(1, 1);
            dic.Add(2, 2);
            var dic2 = dic.Copy(x => x, y => y);
            dic[1] = 12;//change Value
            dic.Remove(2);//remove Value
            Assert.AreEqual(2, dic2.Count);
            Assert.AreEqual(1, dic2[1]);
            Assert.AreEqual(2, dic2[2]);
        }
        [TestMethod, TestCategory("Ext: System.Generic:CopyDictionary")]
        public void CopyDictionary2()
        {
            //? class without copy
            Dictionary<int, hc> dic = new Dictionary<int, hc>();
            dic.Add(1, new hc() { Test = 1 });
            dic.Add(2, new hc() { Test = 2 });
            var dic2 = dic.Copy(x => x, y => y);
            dic[1].Test = 12;//change Value
            dic.Remove(2);//remove Value
            Assert.AreEqual(2, dic2.Count);
            Assert.AreEqual(12, dic2[1].Test);
            Assert.AreEqual(2, dic2[2].Test);
        }
        [TestMethod, TestCategory("Ext: System.Generic:CopyDictionary")]
        public void CopyDictionary3()
        {
            //? class with copy
            Dictionary<int, hc> dic = new Dictionary<int, hc>();
            dic.Add(1, new hc() { Test = 1 });
            dic.Add(2, new hc() { Test = 2 });
            var dic2 = dic.Copy(x => x, y => new hc() { Test = y.Test });
            dic[1] = new hc() { Test = 12 };//change Value
            dic.Remove(2);//remove Value
            Assert.AreEqual(2, dic2.Count);
            Assert.AreEqual(1, dic2[1].Test);
            Assert.AreEqual(2, dic2[2].Test);
        }
        [TestMethod, TestCategory("Ext: System.Generic:CopyDictionary")]
        public void CopyDictionary4()
        {
            //? dictionary is null
            Dictionary<int, hc> dic = null;
            try
            {
                dic.Copy(x => x, y => y);
                Assert.Fail("No exception");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(typeof(ArgumentNullException), ex.GetType());
            }
        }

        //? Help class for instances
        class hc
        {
            public int Test { get; set; }
        }

        [TestMethod, TestCategory("Ext: System.Generic:RemoveItemsAt")]
        public void TestRemoveItemsAt1()
        {
            List<string> list = new List<string>();
            list.Add("item 0");
            list.Add("item 1");
            list.Add("item 2");
            list.Add("item 3");
            list.Add("item 4");
            list.RemoveItemsAt(0, 4, 2);
            Assert.AreEqual(2, list.Count);
            Assert.AreEqual("item 1", list[0]);
            Assert.AreEqual("item 3", list[1]);
        }
        [TestMethod, TestCategory("Ext: System.Generic:RemoveItemsAt")]
        public void TestRemoveItemsAt2()
        {
            List<string> list = new List<string>();
            list.Add("item 0");
            list.Add("item 1");
            list.Add("item 2");
            list.Add("item 3");
            list.Add("item 4");
            list.RemoveItemsAt(1, 3);
            Assert.AreEqual(3, list.Count);
            Assert.AreEqual("item 0", list[0]);
            Assert.AreEqual("item 2", list[1]);
            Assert.AreEqual("item 4", list[2]);
        }
        [TestMethod, TestCategory("Ext: System.Generic:RemoveItemsAt")]
        public void TestRemoveItemsAt3()
        {
            //? source = null
            try
            {
                List<string> list = null;
                list.RemoveItemsAt(1, 3);
                Assert.Fail("No exception");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(typeof(ArgumentNullException), ex.GetType());
            }
        }
        [TestMethod, TestCategory("Ext: System.Generic:RemoveItemsAt")]
        public void TestRemoveItemsAt4()
        {
            //? dictionary is null
            try
            {
                List<string> list = new List<string>();
                list.RemoveItemsAt(null);
                Assert.Fail("No exception");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(typeof(ArgumentNullException), ex.GetType());
            }
        }
    }
}
